package com.zhangchenzhou.room;

import android.app.Application;
import android.arch.persistence.room.Room;

import com.zhangchenzhou.room.database.AppDatabase;

/**
 * Created by 63453 on 2018/3/24.
 */

public class MainApplication extends Application{
    private static MainApplication instance;
    private AppDatabase appDb;
    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        init();
    }

    private void init() {
        //数据库的使用 --》无版本升级的情况
        appDb = Room.databaseBuilder(getApplicationContext(),
                AppDatabase.class, "database-name").build();

        //数据库的使用 --》版本升级的情况
//        Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "database-name")
//                .addMigrations(MIGRATION_1_2, MIGRATION_2_3).build();
    }

    public static MainApplication getInstance(){
        return instance;
    }

    public AppDatabase getAppDb(){
        return this.appDb;
    }

}
